local BaseData = require("data.base.BaseData")
local GemStoneData = class("GemStoneData", BaseData)
local GemStoneUnitData = require("data.GemStoneUnitData")

function GemStoneData:ctor()
    GemStoneData.super.ctor(self)
    self._gemList = {}
end

function GemStoneData:_initData()
    local StoreConst = require("const.StoreConst")
    self._globalGemId = G_StoreManager:getGlobalId(StoreConst.GEMSTONE_GLOBALID)
end

function GemStoneData:_setGemsUnitData(data)
    local unit = self._gemList["k_" .. data.id]
    if not unit then
        unit = GemStoneUnitData.new()
        self._gemList["k_" .. data.id] = unit
    end
    unit:update(data)
end

function GemStoneData:insertData(datas)
    for i = 1, #datas do
        self:_setGemsUnitData(datas[i])
    end
end

function GemStoneData:updateData(datas)
    for i = 1, #datas do
        self:_setGemsUnitData(datas[i])
    end
end

function GemStoneData:deleteData(ids)
    for i = 1, #ids do
        self._gemList["k_" .. ids[i]] = nil
    end
end

function GemStoneData:addData(base_id)
    local data = {}
    data.id = self._globalGemId
    data.base_id = base_id
    self:_setGemsUnitData(data)
    self._globalGemId = self._globalGemId + 1
end

return GemStoneData
